home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 117 / PC Guia 117.iso / Software / Utils / Software2 / Product11 / Setup.exe / MT-3.16-full-en_US / extlib / DateTimePPExtra.pm < prev    next >
Text File  |  2004-04-19  |  1KB  |  72 lines

  1. package DateTime;
  2.  
  3. use strict;
  4.  
  5. require DateTime::LeapSecond;
  6.  
  7. sub _normalize_tai_seconds
  8. {
  9.     return if grep { $_ == INFINITY() || $_ == NEG_INFINITY() } @_[1,2];
  10.  
  11.     # This must be after checking for infinity, because it breaks in
  12.     # presence of use integer !
  13.     use integer;
  14.  
  15.     my $adj;
  16.  
  17.     if ( $_[2] < 0 )
  18.     {
  19.         $adj = ( $_[2] - 86399 ) / 86400;
  20.     }
  21.     else
  22.     {
  23.         $adj = $_[2] / 86400;
  24.     }
  25.  
  26.     $_[1] += $adj;
  27.  
  28.     $_[2] -= $adj * 86400;
  29. }
  30.  
  31. sub _normalize_leap_seconds
  32. {
  33.     # args: 0 => days, 1 => seconds
  34.     my $delta_days;
  35.  
  36.     use integer;
  37.  
  38.     # rough adjust - can adjust many days
  39.     if ( $_[2] < 0 )
  40.     {
  41.         $delta_days = ($_[2] - 86399) / 86400;
  42.     }
  43.     else
  44.     {
  45.         $delta_days = $_[2] / 86400;
  46.     }
  47.  
  48.     my $new_day = $_[1] + $delta_days;
  49.     my $delta_seconds = ( 86400 * $delta_days ) +
  50.                         DateTime::LeapSecond::leap_seconds( $new_day ) -
  51.                         DateTime::LeapSecond::leap_seconds( $_[1] );
  52.  
  53.     $_[2] -= $delta_seconds;
  54.     $_[1] = $new_day;
  55.  
  56.     # fine adjust - up to 1 day
  57.     my $day_length = DateTime::LeapSecond::day_length( $new_day );
  58.     if ( $_[2] >= $day_length )
  59.     {
  60.         $_[2] -= $day_length;
  61.         $_[1]++;
  62.     }
  63.     elsif ( $_[2] < 0 )
  64.     {
  65.         $day_length = DateTime::LeapSecond::day_length( $new_day - 1 );
  66.         $_[2] += $day_length;
  67.         $_[1]--;
  68.     }
  69. }
  70.  
  71. 1;
  72.